// Includes
#include "dstowerdefense.h"

const u8 gfx_cursor[16*16] __attribute__ ((aligned (4))) = {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 

0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,

0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
};
const u16 pal_cursor[8] __attribute__ ((aligned (4))) = { 0x0000, PA_RGB(31,31,31), PA_RGB(15,15,15), 0x0022 };

// Function: main()
int main(int argc, char ** argv)
{
	PA_Init();    // Initializes PA_Lib
	PA_InitVBL(); // Initializes a standard VBL
  PA_InitText(1,1);
  drawable_t cursor;
  drawable_setup(&cursor, 0, 0, 0);
  drawable_load(&cursor, 0, 0, (void*)pal_cursor, (void*)gfx_cursor, OBJ_SIZE_16X16, 1);
  tower_t tower;
  drawable_setup(&tower.drawable, 1, 50, 50);
  drawable_load(&tower.drawable, 0, 1, (void*)pal_tower, (void*)gfx_tower, OBJ_SIZE_16X16, 1);
  PA_SetSpriteRotEnable(0, tower.drawable.sprite, 0);

  u16 angle = 0;

	// Infinite loop to keep the program running
	while (1)
	{
    angle = drawable_get_angle_to(&tower.drawable, &cursor);
    PA_SetRotsetNoZoom(0, 0, angle);
    PA_OutputText(1, 0, 0, "Angle: %d", angle);
    PA_OutputText(1, 0, 2, "Cursor: %d,%d", cursor.position.x, cursor.position.y);
		cursor.position.x += (Pad.Held.Right - Pad.Held.Left);
		cursor.position.y += (Pad.Held.Down - Pad.Held.Up);
    drawable_draw(&cursor);
		PA_WaitForVBL();
	}
	
	return 0;
} // End of main()
